package cn.com.roy.thread.t3_1_3.firstnotify;

public class MyRun {
    private String lock = new String("");
    private Runnable runnable1 = new Runnable() {
        public void run() {
            synchronized (lock) {
                System.out.println("begin wait");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("end wait");
            }
        }
    };
    private Runnable runnable2 = new Runnable() {
        public void run() {
            synchronized (lock) {
                System.out.println("begin notify");
                lock.notify();
                System.out.println("end notify");
            }
        }
    };

    public static void main(String[] args) {

        MyRun run = new MyRun();
        Thread a = new Thread(run.runnable1);
        a.start();

        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Thread b = new Thread(run.runnable2);
        b.start();
    }
}
